<?php
/**
 * 缓存驱动
*/

namespace houze;

class Cache
{
    /**
     * 缓存驱动实例
    */
    private $CacheDriver;
    /**
     * 驱动标识符
    */
    private $DriverName = 'default';
    /**
     * 驱动对应的配置
    */
    private $DriverConfig = [];
    
    /**
     * 选择驱动
    */
    public function __construct($DriverName = null) {
        if ($DriverName) {
            $this->store($DriverName);
        } else {
            $this->store($this->DriverName);
        }
    }

    /**
     * 切换驱动
    */
    public function store($DriverName) {
        $this->DriverConfig = \houze\Config::get('cache.'.$DriverName);
        $class = '\houze\cache\\'. ucfirst(strtolower($this->DriverConfig['type']));
        $this->CacheDriver = new $class($this->DriverConfig);
        
        return $this;
    }

    /**
     * 驱动方法注入
    */
    public function __call($name, $arguments=[]) {
        return call_user_func_array([$this->CacheDriver, $name], $arguments);
    }
}